#include "../terra-ge.h"
#include "../rsrc/bitmap_manager.h"

#ifndef TERRAGE_ANIMATION_H_INCLUDED
#define TERRAGE_ANIMATION_H_INCLUDED

namespace TerraGE {
    class Animation {
        protected:
            bool repeat;
            bool bidirectional;
            bool direction;
            float speed;
            float frame;
            bool active;
            int size;

            ALLEGRO_BITMAP *actual_bit_diffuse;
            ALLEGRO_BITMAP *actual_bit_normal;
            ALLEGRO_BITMAP *actual_bit_height;

            deque<ALLEGRO_BITMAP *> frames_diffuse;
            deque<ALLEGRO_BITMAP *> frames_height;
            deque<ALLEGRO_BITMAP *> frames_normal;

            string name;
        public:
            Animation(Bitmap_Manager *bm, string path, float sp, bool bidir, bool rep);
            ALLEGRO_BITMAP *Get_Actual_Bitmap() {return actual_bit_diffuse;}
            ALLEGRO_BITMAP *Get_Actual_Bitmap_Normal() {return actual_bit_normal;}
            ALLEGRO_BITMAP *Get_Actual_Bitmap_Height() {return actual_bit_height;}

            void Update(float timestep);

            void Start();
            void Resume();
            void Stop();

            void Set_Frame_Percent(float f);
            void Set_Frame(float f);

            string Get_Name() {return name;}

            ~Animation();
    };

    class Animation_Manager {
        protected:
            list<Animation *> animations;
            string path;
            Animation *actual_animation;
            Animation *next_animation;
        public:
            Animation_Manager(Bitmap_Manager *bm, string path);

            ALLEGRO_BITMAP *Get_Actual_Bitmap() {
                if (actual_animation) return actual_animation->Get_Actual_Bitmap();
                return NULL;
            }

            ALLEGRO_BITMAP *Get_Actual_Bitmap_Normal() {
                if (actual_animation) return actual_animation->Get_Actual_Bitmap_Normal();
                return NULL;
            }

            ALLEGRO_BITMAP *Get_Actual_Bitmap_Height() {
                if (actual_animation) return actual_animation->Get_Actual_Bitmap_Height();
                return NULL;
            }

            void Update(float timestep);

            void Start();
            void Resume();
            void Stop();

            void Set_Animation(string nm);
            void Set_Next_Animation(string nm);

            Animation *Get_Animation() {
                return actual_animation;
            }

            string Get_Animation_Name() {
                if (actual_animation) return actual_animation->Get_Name();
                return "";
            }

            ~Animation_Manager();
    };
}


#endif
